<template>
	
	<view>
		<view class="loginForm_box">
			<view class="loginForm_head">
				<u-section title="用户登录" font-size="32" bold line-color="#2F7AE0" :show-line="false" :right="false"></u-section>
			</view>
			<view class="loginForm_con">
				<view class="formPost_con">
					<view class="submitBtn" v-on:click="getPhoneNumber()">本机一键登陆</view>
				</view>
				
				<view class="formPost_con">
					<view class="submitBtn submitBtn2" @click="toLogin()">帐号登陆</view>
				</view>
				<view class="formHelper_con">
					<view class="regBtn" @click="regClick">立即注册</view>
					<view class="forgetBtn">忘记密码</view>
				</view>
			</view>
		</view>
	
	</view>
	
</template>

<script>
	// #ifdef APP-PLUS
	var MNOModule = uni.requireNativePlugin("Esand-MNOModule")
	var secretKey;
	var authUIConfigJson = "{\n" +
	        "    \"prefersStatusBarHidden\":true,\n" +
	        "    \"logoImgPath\":\"cscs\"\n" +
	        "}"
	// #endif
		
	export default {
		data() {
			return {
				msg: "日志"
			}
		},
		onReady(){
			this.getPhoneNumber();
		},
		methods: {
			
			// 注册
			regClick() {
				uni.navigateTo({
					url: './reg'
				})
			},
			
			toLogin(){
				uni.redirectTo({
					url:'/pages/account/login'
				})
			},
			getPhoneNumber: function(e) {
				let platform=uni.getSystemInfoSync().platform
				if(platform=='ios'){
					authUIConfigJson = "{\"prefersStatusBarHidden\":true,\"logoImage\":\"logo\",\"checkBoxIsChecked\":true,\"logoWidth\":10.11123,\"logoHeight\":11.11,\"logoTopOffetY\":10.123,\"numberColor\":\"0x0000FF\",\"navTitle\":\"cscscscscs\",\"navTitleColor\":\"0x0000FF\",\"navTitleFont\":20}"
					// 密钥是和APP绑定的，需要向服务提供商申请，可加微信：esand_info, ANDROID和IOS的密钥不一样
					secretKey = "0wX1qyA0sPZh/sbTZPPGD8ZjlS2iVVVN+q/rLJ3H4brZvvuhUtD9NbJ+X0yB8RFlb0PJ+irtuW4B/WEOQcHrqO0vFvjV9DXotA7CgVi5YNyDp1RfevGNB5AZ6gdC7eWvv9POYC16F8MmvFS1Qh1Fno86d34zgjwxZkf1vpOJQKoMqNvYWkWkkeK+VeIxWb13IJ/mzYF5DPGxoZV/Zd2jZGy8ci8y4evlOMYczAjpfZAXOMCfylWytLuVbX0lQC71cCbdmzf2pBc="
				} else if(platform=='android') {
					let authUIConfig = {}
					authUIConfig.navColor = "0x00000000"
					authUIConfig.navTextColor = "0xFF000000"
					authUIConfig.isLightColor = true
					authUIConfig.navReturnImgWidth
					authUIConfig.navReturnImgWidth = 206
					authUIConfig.navReturnImgHeight = 20
					authUIConfig.navReturnScaleType = 6
					authUIConfig.navReturnImgPath = "back"
					authUIConfig.logoImgPath = "static/wulianwang-.png"
					authUIConfigJson = JSON.stringify(authUIConfig)
					// 这里客制化一键登录授权页面,详细可参考: https://esandinfo.yuque.com/books/share/5ddd649d-2afa-48e6-bb07-633105dfec88?#
					// authUIConfigJson = "{\"privacyState\":true,\"logoImgPath\":\"cscs\",\"navHidden\":true,\"iconLayoutOffSetY\":600,\"iconLayoutWidth\":150}"
					// 密钥是和APP绑定的，需要向服务提供商申请，可加微信：esand_info, ANDROID和IOS的密钥不一样
					secretKey = "VozMlbkqE2dCZfko+Tdz0vbwkv3jgBTux7Hhb1FIvqK1Pbhku30G9rK4R7oiWynIZMt3MGIzeAJO9eP/8N7jk5SeMLV+oFDF4dKrHMynzaxbtHMVKOxd0K4wTc2hIw5lDCHfmduIhk0Cuxvg6MD/5iTHlPZk8bA0T+mrec9EcsCWaoRGOzRNVdyrIkaX3nAGGyt3tMCgnKsJhGG40pSQ7P6fptgD3ZU2XP6k0XBgbQ4VyRpquLRNFbjmas0qN/OPSl3zD1cq2iaOVrlZp/NzMb5gIVheufjLZ8bqC40wYL8hM3Peg2Ltjbo4PlGaZrgk"
				}
				MNOModule.getPhoneNum({
					'secretKey': secretKey,
					'authUIConfigJson': authUIConfigJson

				}, (ret) => {
					if (ret.code == '0') {
						let dataBody = ret.data
						
						let dataBodyJson = JSON.parse(dataBody)
						console.log(dataBodyJson)
						uni.request({
							url: 'http://edismno.market.alicloudapi.com/mno/getMobile',
							method: 'POST',
							data: {
								'deviceModel': dataBodyJson.deviceModel,
								'packageId':dataBodyJson.packageId,
								'platform':dataBodyJson.platform,
								'token':dataBodyJson.token,
								'transId':dataBodyJson.transId,
								'appName':dataBodyJson.appName,
								'phoneNum':dataBodyJson.phoneNum
							},
							header: {
								// APPCODE是阿里云网关密钥，不建议直接在APP端直接请求阿里云网关，因为会泄漏APPCODE, 可以把这段逻辑写到服务器端，然后再请求服务器
								'Authorization': 'APPCODE 2fe2f1e1e50b4f8d8c9ff233eabf21a5',  // appcode的获取可参考： https://esandinfo.yuque.com/docs/share/13ad611e-b9c3-4cf8-a9a8-fe23a419312e?# 《如何获取APPCODE/APPKEY&APPSECRET》
								'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
							},
							success: (res) => {
								res.header
								var rspMsg = JSON.stringify(res.data)
								console.log(res);
								// console.log('网络请求成功' + rspMsg)
								// var rspMsgData = JSON.stringify(rspMsg);
								var mobile=res.data.msg
								// uni.showModal({
								// 	title: "获取结果成功",
								// 	content: JSON.stringify(res),
								// })
								
								this.mobileLogin(mobile);
								
								
							}
						})
					}else{
						console.log(ret)
						this.msg = JSON.stringify(ret);
					}
				})
			},
			
			mobileLogin(mobile) {
				var _this = this;
				console.log(mobile)
				// console.log('验证通过');
				var postData={
					mobile: mobile,
					password: 'daqin_'+mobile,
				}
				console.log(postData);
				_this.$u.post('/api/supplier.login/mobileLogin', postData).then(res => {
					console.log('==登录==');
					console.log(res);
					console.log(res.extend.token);
					// 缓存token
					uni.setStorageSync('token', res.extend.token);
					uni.showToast({
						title: res.msg,
						duration: 2000
					});
					setTimeout(function() {
						// uni.navigateBack({
						// 	delta: 1
						// })
						uni.reLaunch({
							url:'/pages/index/index'
						})
					}, 2000)
				}).catch((res) => {
					console.log(res);
				})
			
				
			},
		}
	}
</script>

<style>
	page {
		background-color: #fff;
	}
</style>
<style>
   /* .content {
        position: absolute;
        width: 100%;
        height: 100%;
    }

    .esand_logo {
        margin-top: 100rpx;
        margin-bottom: 100rpx;
        width: 200rpx;
        height: 200rpx;
        align-self: center;
    }

    .item {
        margin-bottom: 15rpx;
        margin-top: 15rpx;
        width: 400rpx;
    }

    img {
        position: relative;
        margin-top: 50rpx;
        width: 600rpx;
        height: 400rpx;
    }

    label {
        display: block;
        margin-top: 10rpx;
    }

    textarea {
        margin-top: 20rpx;
        height: 400rpx;
    } */
	
	
	.loginTop_box {
		width: 100%;
		height: 350rpx;
		box-sizing: border-box;
		overflow: hidden;
		position: relative;
	}
	.loginTop_box image{
		width: 100%;
		height: 100%;
	}
	
	.loginTop_con {
		width: 100%;
		color: #fff;
		position: absolute;
		z-index: 999;
		top: 20%;
		left:30rpx;
	}
	
	.loginTit {
		font-size: 36rpx;
	}
	
	.loginDesc {
		font-size: 36rpx;
		margin-top: 20rpx;
	}
	
	.loginForm_box {
		padding: 30rpx;
		background-color: #fff;
		overflow: hidden;
	}
	
	.loginForm_head {
		padding: 20rpx 0;
	}
	
	.formPost_con {
		margin-top: 50rpx;
	}
	
	.formHelper_con {
		padding: 50rpx 0;
		font-size: 28rpx;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	
	.regBtn {
		color: #288aff;
	}
	
	.forgetBtn {
		color: #999;
	}
	
	.submitBtn2{
		background-image: linear-gradient(to right, #ffc820, #ffaa00);
	}
</style>
